﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.IO;

public partial class Controls_ucWeather : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadWeather();
            loadHotline();
        }
    }

    protected void loadWeather()
    {
        string fDanang = "http://vnexpress.net/ListFile/Weather/DaNang.xml";
        string fHCM = "http://vnexpress.net/ListFile/Weather/HCM.xml";
        string fHanoi = "http://vnexpress.net/ListFile/Weather/Hanoi.xml";
        loadInfo(fDanang, "DaNang");
        loadInfo(fHanoi, "HaNoi");
        loadInfo(fHCM, "HCM");
    }

    protected void loadInfo(string path, string province)
    {
        XmlDocument doc = new XmlDocument();
        try
        {
            doc.Load(path);
        }
        catch (Exception ex)
        {
            return;
        }
        XmlNode root = doc.DocumentElement;
        XmlNodeList list = root.ChildNodes;
        int count = list.Count;
        if (count >= 7)
        {
            if (province == "HaNoi")
            {
                temp_hn.InnerHtml = getNumber(list.Item(1).InnerText.ToString()) + getNumber(list.Item(2).InnerText.ToString()) + "<sup>o</sup>C";
                img_hn.Src = "http://vnexpress.net/Images/Weather/" + list.Item(0).InnerText.ToString();
            }
            else if (province == "DaNang")
            {
                temp_dn.InnerHtml = getNumber(list.Item(1).InnerText.ToString()) + getNumber(list.Item(2).InnerText.ToString()) + "<sup>o</sup>C";
                img_dn.Src = "http://vnexpress.net/Images/Weather/" + list.Item(0).InnerText.ToString();
            }
            else
            {
                temp_hcm.InnerHtml = getNumber(list.Item(1).InnerText.ToString()) + getNumber(list.Item(2).InnerText.ToString()) + "<sup>o</sup>C";
                img_hcm.Src = "http://vnexpress.net/Images/Weather/" + list.Item(0).InnerText.ToString();
            }

        }
    }

    protected void loadHotline()
    {
        try
        {
            string path = Server.MapPath("~/upload/xml/hotline.xml");
            if (File.Exists(path))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path);
                XmlNode root = doc.DocumentElement;
                XmlNodeList list = root.ChildNodes;
                //txtName1.Text = list.Item(0).Attributes[0].InnerText;
                hn_hot.InnerText = list.Item(0).Attributes[1].InnerText;
                //txtName2.Text = list.Item(1).Attributes[0].InnerText;
                hcm_hot.InnerText = list.Item(1).Attributes[1].InnerText;
            }
        }
        catch (Exception ex)
        {
            
        }
    }

    protected string getNumber(string split)
    {
        return split.Replace(".gif", "");
    }
}